package com.sanyang.lawyer.ResultApi;

import lombok.Data;
import lombok.ToString;

import javax.xml.transform.Result;

/*
    统一返回结果类型
 */
@Data
@ToString
public class ResponseResult<T> {
    
    private int code; //状态码
    
    private String messgage; //状态信息
    
    private T data;//返回数据

    //成功时候调用的构造方法
    private ResponseResult(T data) {
        this.code = 0;
        this.messgage = "success";
        this.data = data;
    }
    //错误时候调用的构造方法
    private ResponseResult(CodeMsg codeMsg) {
        this.code = codeMsg.getCode();
        this.messgage = codeMsg.getMessage();
        this.data = null;
    }

    //成功时候的调用
    public static <T> ResponseResult<T> success(T data){
        return new ResponseResult<T>(data);
    }
    
    
    //失败时候的调用
    public static <T> ResponseResult<T> error(CodeMsg codeMsg){
        return new ResponseResult<T>(codeMsg);
    }
    
}
